package com.browsesoft.log;

import java.io.IOException;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.RollingFileAppender;

/**
 * 系统日志
 */
public class SystemLogger {
	/**
	 * 单例
	 */
	private static SystemLogger instance = new SystemLogger();

	/**
	 * 对应的日志
	 */
	private Logger logger = Logger.getLogger(SystemLogger.class);

	/**
	 * 单例构造函数
	 */
	private SystemLogger() {
		try {
			PatternLayout layout = new PatternLayout(
					"%d{yyyy-MM-dd hh:mm:ss} %m%n");
			FileAppender appender = new RollingFileAppender(layout,
					"system.log", true);
			logger.addAppender(appender);
		} catch (IOException ex) {
			throw new RuntimeException(ex);
		}
	}

	/**
	 * 返回单例
	 */
	public static SystemLogger getInstance() {
		return instance;
	}

	/**
	 * 记录异常信息
	 */
	public void logException(Exception e) {
		logger.error("Exception", e);
	}

	/**
	 * 记录一般信息
	 */
	public void logMessage(String msg) {
		logger.error(msg);
	}
}